﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SalePromotion.Extensions;
using SalePromotion.Service;
using SalePromotion.eBay;
using eBay.Service.Core.Soap;

namespace SalePromotion.Models
{
    public partial  class EBayListingModel
    {
        public EBayListingModel()
        {
            SortBys = SelectListHelper.GetSortBy();
            ListingFormats = SelectListHelper.GetListingFormat();
            EBayListings= new List<ItemInfoModel>();
        }
        public IEnumerable<ItemInfoModel> EBayListings { get; set; }
        public bool HasItems
        {
            get { return EBayListings.Any(); }
        }

        public IEnumerable<SelectListItem> SortBys { get; set; }
        public IEnumerable<SelectListItem> ListingFormats { get; set; }

        public string SortBy { get; set; }
        public string ListingFormat { get; set; }

        public int? Id { get; set; }

        public long SelectedCount
        {
            get { return EBayListings.Count(listing => listing.IsSelected); }
        }
    }

    public class ItemInfoModel
    {
        public ItemInfoModel(ItemInfo item, IEnumerable<SaleListing> saleListings)
        {
            ItemId = item.ItemId;
            PicitureURL = item.PicitureURL;
            Title = item.Title;
            CurrentPrice = item.CurrentPrice;
            Qty = item.Qty;
            ShippingCost = item.ShippingCost;
            ItemFormat = item.ItemFormat;
            EndDate = item.EndDate.ToString("MM/dd/yyyy HH:mm:ss");
            IsSelected = saleListings.Any(saleListing => saleListing.ItemId == item.ItemId);
        }

        public string ItemId { get; set; }

        public string PicitureURL
        {
            get { return string.IsNullOrWhiteSpace(pictureUrl) ? "" : pictureUrl; }
            set { pictureUrl = value; }
        }
        private string pictureUrl;

        public string Title { get; set; }
        public bool IsSelected { get; set; }

        public string CurrentPrice { get; set; }

        public int Qty { get; set; }

        public string ShippingCost { get; set; }

        public string ItemFormat { get; set; }
        public string ItemFormatImageUrl
        {
            get
            {

                if (ItemFormat == ListingTypeCodeType.Chinese.ToString()) return  "~/Content/Img/iconAuction_16x16.gif";
                return "~/Content/Img/iconFixedprice_16x16.gif";

            }
        }

        public string EndDate { get; set; }

    }

}